package com.mxgraph.examples.swing.editor;
import java.awt.event.ActionEvent;
import java.io.IOException;

import javax.swing.JOptionPane;

import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;

public class PingTelnetSSH
{
	/*static String routerIP = null;
	static String vlaueOfSelectedItem;
	static String sysType;*/
	private static String OS = System.getProperty("os.name").toLowerCase();
	PingTelnetSSH(String routerIP, String op ) throws IOException
    {
		String selectOption=op;
		if(selectOption=="Ping")
		{
    	 System.out.println("Ping Starts...");
       /* if (vlaueOfSelectedItem.startsWith("["))
		{
			//routerIP = vlaueOfSelectedItem;
			sysType="Switch";
			
			String x= (String)vlaueOfSelectedItem;
       		//String x= (String);
       	    System.out.println( x.replace("[",""));
       	    x = x.replace("[","");
       	    System.out.println( x.replace("]",""));
       	    String j;
       	    j=x.replace("]","");
       	    System.out.println(j);
       	   routerIP = j;
*/
        String ipAddress = routerIP;
    	if (isWindows()) {
    		Runtime.getRuntime().exec(new String[]
    		           {"cmd", "/k", "start", "cmd", "/c", "\"ping " + ipAddress+ " & pause\""});
    		} 

         else if (isUnix()) {
        	 Runtime.getRuntime().exec("xterm -e ping "+ ipAddress);

        } 
		}
		else if(selectOption=="Telnet")
		{
			String ipAddress = routerIP;
			if (isWindows()) {
				Runtime.getRuntime().exec(
						new String[]{"cmd", "/k", "start", "cmd", "/c", "telnet " + ipAddress});
			}

			else if (isUnix()) {
				Runtime.getRuntime().exec("xterm -hold -e telnet "+ ipAddress);

			}
		}
		else if(selectOption=="SSH")
		{
			String ipAddress = routerIP;
			if (isWindows()) {
				System.out.println("not possible");
			}
			else if (isUnix()) {
				Runtime.getRuntime().exec("xterm -hold -e ssh "+ ipAddress);

			}
		}
		}
    
    private static boolean isWindows() {
        return (OS.indexOf("win") >= 0);
    }

    
    

    private static boolean isUnix() {
        return (OS.indexOf("nux") >= 0);
    }
}